package yuan;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryNTimes;
import org.apache.curator.retry.RetryOneTime;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/09/12 20:14
 */


public class CuratorConnection {
    public static final String ip = "192.168.190.128:2181";
    public static void main(String[] args) {
        //session 重连策略
        //3s后重连，重连一次
        //RetryOneTime retryOneTime = new RetryOneTime(3000);

        //每三秒重连一次，重连三次
        //RetryNTimes retryNTimes = new RetryNTimes(3, 3000);

        /* 每3秒重连一次，总等待时间超过10秒后停止重连
        RetryPolicy retryPolicy=new RetryUntilElapsed(10000,3000);
        * */

        ExponentialBackoffRetry backoffRetry = new ExponentialBackoffRetry(1000, 3);

        CuratorFramework client = CuratorFrameworkFactory
                .builder()
                .connectString(ip)
                .sessionTimeoutMs(5000)
                .retryPolicy(backoffRetry)
                .namespace("create")
                .build();
        client.start();
        System.out.println(client.isStarted());
        client.close();

    }
}
